package com.aiapphub.BaseCode.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * knife4j 配置
 *
 */
@Configuration
@EnableSwagger2
public class Knife4jConfig {

    /**
     * 创建Swagger Docket对象
     * @return Swagger Docket对象
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.aiapphub.SystemCode.controller")) // 扫描的包路径
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置Swagger文档基本信息
     * @return Swagger文档基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SpringBoot项目 后台服务API接口文档") // 文档标题
                .description("使用 knife4j 搭建的后台服务API接口文档") // 文档描述
                .termsOfServiceUrl("http://localhost:8888/") // 服务条款url
                .version("1.0.0") // 版本号
                .build();
    }
}